package cn.jbolt.ai.klb;


import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public enum FileState {

    NO_TRAIN(100, "未训练"),
    TRAINING(200, "训练中"),
    TRAIN_SUCCESS(300, "训练成功"),
    TRAIN_ERROR(400, "训练失败"),
    EMBEDDING(500, "向量化中"),
    EMBEDDING_SUCCESS(600, "向量化成功"),
    EMBEDDING_ERROR(700, "向量化失败");

    private int code;
    private String description;


    // 私有构造函数
    private FileState(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code查找对应的description
     * @param code
     * @return
     */
    public static FileState getByCode(int code) {
        if (code == 0) {
            throw new IllegalArgumentException("FileType code 不能为 null");
        }
        return Arrays.stream(values())
                .filter(type -> type.getCode()==code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未找到匹配的 FileType : " + code));
    }



    public static List<Map<String, Object>> toList() {
        return java.util.Arrays.stream(FileState.values())
                .map(type -> {
                    Map<String, Object> map = new java.util.HashMap<>();
                    map.put("value", type.getCode());
                    map.put("text", type.getDescription());
                    return map;
                })
                .collect(Collectors.toList());
    }
}

